package com.example.jucsample;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zhenwei.wu
 * @date 2021/3/17
 */
public class Test {

    public static void main(String[] args) throws Exception {
        ReentrantLock lock = new ReentrantLock();
        Condition read = lock.newCondition();
        Condition write = lock.newCondition();
        new Thread(() -> {
            while (true) {
                try {
                    lock.lock();
                    System.out.println("read");
                    read.await();
                    System.out.println("read signal");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            }

        }).start();

        Thread.sleep(3000L);
        lock.lock();
        read.signalAll();
        lock.unlock();

    }

}
